//
//  TestingPaperView.m
//  JW_BasePorject
//
//  Created by JW on 2018/7/3.
//  Copyright © 2018年 JW. All rights reserved.
//

#import "TestingPaperView.h"


#import "PaperProgressView.h"
#import "TestingPaperCollectionViewCell.h"

@interface TestingPaperView ()<UICollectionViewDataSource, UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>

@property (nonatomic,strong)PaperProgressView *progressView;

@property (nonatomic, weak) UICollectionView *mainView; //显示图片的collectionView
@property (nonatomic, weak) UICollectionViewFlowLayout *flowLayout;


@end

@implementation TestingPaperView


- (void)initConfigureView {
    self.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.progressView];
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT - NavigationBarHeight - 40);
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    _flowLayout = flowLayout;
    
    UICollectionView *mainView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, NavigationBarHeight + 40, SCREEN_WIDTH, SCREEN_HEIGHT - NavigationBarHeight - 40) collectionViewLayout:flowLayout];
    
    mainView.backgroundColor = [UIColor whiteColor];
    mainView.pagingEnabled = YES;
    mainView.showsHorizontalScrollIndicator = NO;
    mainView.showsVerticalScrollIndicator = NO;
    [mainView registerClass:[TestingPaperCollectionViewCell class] forCellWithReuseIdentifier:@"TestingPaperCollectionViewCell"];
    
    mainView.dataSource = self;
    mainView.delegate = self;
    mainView.scrollsToTop = NO;
    [self addSubview:mainView];
    _mainView = mainView;
    
}

// 当滚动视图动画完成后，调用该方法，如果没有动画，那么该方法将不被调用
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView{
    [self scrollViewDidEndDecelerating:self.mainView];
}

//关联滚动视图与下图显示的标题
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
     NSInteger pageindex = scrollView.contentOffset.x/SCREEN_WIDTH;
    self.progressView.currentIndex = pageindex;
}


#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    //    BTLog(@"%@",self.selectTopicArray);
    return self.dataArray?self.dataArray.count:0;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * CellIdentifier = @"PublicCourseCollectionCell";
    TestingPaperCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
//    cell.publicCourseModel = self.selectPublicClassArray[indexPath.row];
    
    return cell;
}



- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{

    
}



- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        
        [self initConfigureView];
    }
    return self;
}


- (PaperProgressView *)progressView{
    if (_progressView == nil) {
        _progressView = [[PaperProgressView alloc] initWithFrame:CGRectMake(0, NavigationBarHeight, SCREEN_WIDTH, 40)];
         _progressView.currentIndex = 0;
    }
    return _progressView;
}
@end
    
